package com.b1502.store2.adapter;

import android.content.Context;

import android.view.View;


import android.view.ViewGroup;
import android.widget.BaseAdapter;


import android.widget.ImageView;


import android.widget.TextView;



import com.b1502.store2.R;
import com.b1502.store2.model.bean.OrderBean;


import com.b1502.store2.util.ImageLoaderUtils;

import com.b1502.store2.util.UrlUtil;
import com.nostra13.universalimageloader.core.DisplayImageOptions;


import com.nostra13.universalimageloader.core.ImageLoader;



import org.mym.plog.PLog;

import java.util.List;

/**
 * 类描述:
 * 作者：陈文梦
 * 时间:2017/3/1 11:03
 * 邮箱:18310832074@163.com
 */

public
class
ConfirmAdapter extends BaseAdapter {

    private Context context;
    private List<OrderBean.OrderDetailsBean> orderDetailsBeanList;
    private DisplayImageOptions options;

    public ConfirmAdapter(Context context, List<OrderBean.OrderDetailsBean> orderDetailsBeanList) {
        this.context = context;
        this.orderDetailsBeanList = orderDetailsBeanList;
        options = ImageLoaderUtils.initOptions();
    }

    @Override
    public int getCount() {
        //PLog.e(orderDetailsBeanList.size()+"  数据长度");
        return orderDetailsBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return orderDetailsBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        MyViewHolder myViewHolder = null;
        if (convertView == null) {
            myViewHolder = new MyViewHolder();
            convertView=View.inflate(context, R.layout.confirm_order_item,null);
            myViewHolder.confirm_image= (ImageView) convertView.findViewById(R.id.confirm_image);
            myViewHolder.confirm_name= (TextView) convertView.findViewById(R.id.confirm_name);
            myViewHolder.confirm_price= (TextView) convertView.findViewById(R.id.confirm_price);
            myViewHolder.confirm_num= (TextView) convertView.findViewById(R.id.confirm_num);
            convertView.setTag(myViewHolder);
        }else {

            myViewHolder = (MyViewHolder) convertView.getTag();

        }

        ImageLoader.getInstance().displayImage(UrlUtil.getImageUrl(orderDetailsBeanList.get(position).ImageUrl),myViewHolder.confirm_image,options);
        myViewHolder.confirm_name.setText(orderDetailsBeanList.get(position).ProductName);
        myViewHolder.confirm_price.setText("￥"+orderDetailsBeanList.get(position).Price);
        myViewHolder.confirm_num.setText("X "+orderDetailsBeanList.get(position).Quantity);
        return convertView;
    }

    class MyViewHolder {

        ImageView confirm_image;
        TextView confirm_name, confirm_price, confirm_num;

    }
}
